package com.whisperly.echotalk.starryb.netWorkUtils;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import com.whisperly.echotalk.bllmodel.AiFeedback;
import com.whisperly.echotalk.bllmodel.ReturnedValue;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.io.IOException;

@Keep
public class NetworkUtils {

    private static final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://chen88.top")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    public static void postFeedback(String userName,String feedbackType, String feedbackContent, final NetworkCallback callback) {
        ApiService service = retrofit.create(ApiService.class);
        
        AiFeedback feedback = new AiFeedback();
        feedback.setFeedbackType(feedbackType);
        feedback.setUserName(userName);
        feedback.setFeedbackContent(feedbackContent);

        Call<ReturnedValue> call = service.postFeedback(feedback);
        call.enqueue(new retrofit2.Callback<ReturnedValue>() {
            @Override
            public void onResponse(@NonNull Call<ReturnedValue> call, @NonNull retrofit2.Response<ReturnedValue> response) {
                if (response.isSuccessful()) {

                    callback.onSuccess(response.body());
                } else {

                    callback.onFailure(new IOException("Unexpected code " + response));
                }
            }

            @Override
            public void onFailure(@NonNull Call<ReturnedValue> call, @NonNull Throwable t) {

                callback.onFailure(t);
            }
        });
    }
}
